package com.yuan.SMS.controller;

import com.alibaba.fastjson.JSON;
import com.yuan.SMS.bean.QueryInfo;
import com.yuan.SMS.bean.Student;
import com.yuan.SMS.dao.StudentDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
public class OneStudentController {
    @Autowired
    StudentDao oneSdao;

    @RequestMapping("/findOne")
    @CrossOrigin("http://localhost:8080")
    public String getStudent(QueryInfo queryInfo){
        String flag = "error";
        List<Student> student = oneSdao.findOneStudent(queryInfo.getStudentNo());
        HashMap<String, Object> res = new HashMap<>();
        if(student!=null) {
            flag = "ok";
        }
        res.put("flag",flag);
        res.put("data",student);
        return JSON.toJSONString(res);
    }
}
